package pers.mihao.quickstream.common.exception;

import pers.mihao.quickstream.common.constans.CommonConstant;

/**
 * 自定义错误类型
 *
 * @author mihao
 */
public class BaseException extends RuntimeException {

    private Integer code;
    private String mes;

    public BaseException(Exception e) {
        super(e);
        this.code = CommonConstant.ERROR;
    }

    public BaseException(Integer code) {
        this.code = code;
        this.mes = super.getMessage();
    }


    public BaseException(String mes) {
        super(mes);
        this.mes = mes;
        this.code = CommonConstant.ERROR;
    }

    public BaseException(Integer code, String mes) {
        this.code = code;
        this.mes = mes;
    }

    public BaseException(ExceptionInfo exceptionInfo) {
        this.code = exceptionInfo.getCode();
        this.mes = exceptionInfo.getMes();
    }


    public BaseException() {
        this.code = CommonConstant.ERROR;
        this.mes = CommonConstant.DEFAULT_ERROR;
    }

    public Integer getCode() {
        return code;
    }

    public String getMes() {
        return mes;
    }

    public interface ExceptionInfo {
        Integer getCode();

        String getMes();
    }

    public enum CommonError implements ExceptionInfo {

        PARAMS_ERROR(50001, "参数错误");

        private Integer code;

        private String mes;

        CommonError(Integer code, String mes) {
            this.code = code;
            this.mes = mes;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @Override
        public String getMes() {
            return mes;
        }
    }
}
